package com.lcsu.myThread;

import com.alibaba.fastjson.JSON;

import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

public class myTime {
    private static volatile int count = 0;

    class TimerTaskCas extends TimerTask {
        @Override
        public void run() {
            count = (count + 1) % 2;
            System.out.println("boob Boom" + JSON.toJSONString(Thread.currentThread().getName()));
            new Timer().schedule(new TimerTaskCas(), 2000 + 2000 * count);
        }
    }

    public void mTest() {
        Timer timer = new Timer();
        timer.schedule(new TimerTaskCas(), 200 + 200 * count);
        while (true) {
            System.out.println(new Date().getTime());
            try {
                System.out.println(JSON.toJSONString(Thread.currentThread().getName()));
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        }
    }
}
